<?php
  /**
   *
   */
  trait Regular
  {
      public function reg_name($name){
        $reg = '/^[a-zA-Z0-9_]*$/';
        if (preg_match($reg,$name)) {
          echo "<script>alert('right!')</script>";
        }else{
          echo "<script>alert('wrong!')</script>";
        }
      }

      public function reg_email($email){
        $reg = '/^[\w]+@[\w]+\.[\w]+$/';
        if (preg_match($reg,$email)) {
          echo "<script>alert('right!')</script>";
        }else{
          echo "<script>alert('wrong!')</script>";
        }
      }

      public function reg_img($img){
        $reg = '/^[\w]+\.[jpg|png|gif]+$/i';
        if (preg_match($reg,$img)) {
          echo "<script>alert('right!')</script>";
        }else{
          echo "<script>alert('wrong!')</script>";
        }
      }

      public function reg_url($url){
        //http://my.project.com/mianshiti/W3cSchool.class.php
        $reg = '/^[http|ftp|https]+\:\/\/[\w]+\.[\w]+\.[\w]+[\w\/\.]*$/';
        if (preg_match($reg,$url)) {
          echo "<script>alert('right!')</script>";
        }else{
          echo "<script>alert('wrong!')</script>";
        }
      }
  }

 ?>
